

/**
 * @param {number[]} nums
 * @return {number[][]}
 */
var permute = function(nums) {
    let n = nums.length;
    let res = [];
    let tmpPath = [];
    let num = 0;
    let backTrack = (tmpPath) => {
        if (tmpPath.length == n) {
            res.push(tmpPath);
            return;
        }
        for (let i=0; i<n; i++) {
            num++
            if (!tmpPath.includes(nums[i])) {
                tmpPath.push(nums[i]);
                backTrack(tmpPath.slice());
                tmpPath.pop();
            }
        }
    }
    backTrack(tmpPath);
    console.log(num)
    return res;
}

let x = permute([1, 2, 3, 4])
console.log(x)